//
//  EditImportSignsViewController.m
//  安好
//
//  Created by 马晓良 on 14-11-27.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "EditImportSignsViewController.h"
#import "SignsDataCell.h"
#import "BloodPressureCell.h"
#import "ImportSignDatailViewController.h"
#import "MyHealthLogModel.h"
#import "BaseSignDetailsViewController.h"
#import "UserId.h"
@interface EditImportSignsViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSInteger pages;
}
/**
 *  分别用来显示不同数据
 */
@property (strong, nonatomic) IBOutlet UITableView *editImportSignsTableView;
/**
 *  左右naviBar的button
 */
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UIButton *editButton;

/**
 *  删除的数据的字典
 */
@property (nonatomic, strong) NSMutableDictionary *deleteDic;
/**
 *  获取请求来的数据对象存入该数组中
 */
@property (nonatomic, strong) NSMutableArray *healthDataSourceArray;
@property (nonatomic, strong) NSIndexPath *selfIndexpath;
@end

@implementation EditImportSignsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    pages = 1;
    self.selfIndexpath = [[NSIndexPath alloc] init];
    [self getCurrentTypeStr];
     [self _parseHealthDataSource];
    MyNSLog("%@类型数%@", self.naviTitleStr,self.currentTypeStr);
    self.navigationItem.title = self.naviTitleStr;
    self.editImportSignsTableView.dataSource = self;
    self.editImportSignsTableView.delegate = self;
    self.editImportSignsTableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    [self setNaviBarAttribute];
    editImportSignsChange = NO;
    controlMethod = NO;
    [self.editImportSignsTableView addFooterWithTarget:self action:@selector(_parseHealthDataSource)];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    self.navigationController.navigationBar.translucent = NO;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    self.navigationController.navigationBar.translucent = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 设置naviBar 并实现左右naviBar button方法 -
- (void)setNaviBarAttribute{
    /**
     *  设置左NaviBar和右naviBar
     */
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
    self.editButton.titleLabel.font = [UIFont systemFontOfSize:15];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.backButton.titleLabel.font = [UIFont systemFontOfSize:15];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.editButton];
}

/**
 *  返回主页面
 */
- (void)handleBackButtonAction{
//    if (!controlMethod) {
        [self.navigationController popViewControllerAnimated:YES];
//    }else{
//
//    }
    
}

/**
 *  编辑按钮
 */
- (void)handleEditButtonAction{
    if (!editImportSignsChange) {
        editImportSignsChange = YES;
        [self.backButton setImage:[UIImage imageNamed:@"公用_返回"] forState:UIControlStateNormal];
        UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
        self.navigationItem.leftBarButtonItem = leftBarButtonItem;
//        self.backButton.frame = CGRectMake(0, 0, 23, 23);
        [self.editButton setTitle:@"取消" forState:UIControlStateNormal];
    }
    else{
        editImportSignsChange = NO;
        [self.backButton setImage:[UIImage imageNamed:@"公用_返回"] forState:UIControlStateNormal];
        self.backButton.frame = CGRectMake(0, 0, 23, 23);
        UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
        self.navigationItem.leftBarButtonItem = leftBarButtonItem;
        [self.editButton setTitle:@"编辑" forState:UIControlStateNormal];

    }
    [self.editImportSignsTableView reloadData];
    
    if (!controlMethod) {
        controlMethod = YES;
    }else{
        // 然后执行数据上传
        MyNSLog("上传数据");
        controlMethod = NO;
       
    }

    
}


#pragma mark - tableView的代理方法 -

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.naviTitleStr isEqualToString:@"血压"]) {
        if (kScreenWidth == 414) {
            return 72;
        }else{
            return 60;
        }
    }else{
        if (kScreenWidth == 414) {
            return 54;
        }else{
            return 44;
        }
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.healthDataSourceArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SignsDataCell *cell = [tableView dequeueReusableCellWithIdentifier:@"signsDataCell"];
    BloodPressureCell *bloodCell = [tableView dequeueReusableCellWithIdentifier:@"Blood pressure"];
    if (!cell) {
        if (kScreenWidth == 414) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"SignsDataCell" owner:self options:nil] lastObject];
        }else{
             cell = [[[NSBundle mainBundle] loadNibNamed:@"SignsDataCell" owner:self options:nil] firstObject];
        }
    }
    if (!bloodCell) {
        if (kScreenWidth == 414) {
            bloodCell = [[[NSBundle mainBundle] loadNibNamed:@"BloodPressureCell" owner:self options:nil] lastObject];
        }else{
            bloodCell = [[[NSBundle mainBundle] loadNibNamed:@"BloodPressureCell" owner:self options:nil] firstObject];
        }
    }
    
    MyHealthLogModel *healthModel = [self.healthDataSourceArray objectAtIndex:indexPath.row];
    //  获取时间
    NSString *timeString = [self getDate:healthModel.dateline];
    
    cell.timeLabel.text = timeString;
    if ([self.currentTypeStr intValue] == 6) {
        // 呼吸速率
        cell.contentLabel.text = [NSString stringWithFormat:@"%@次/分",healthModel.respiration];
    }else if ([self.currentTypeStr intValue] == 4){
        // 记步记录
        if (indexPath.row == 0) {
            cell.contentLabel.text = [NSString stringWithFormat:@"%@步",healthModel.pedometer];
        }else{
            cell.contentLabel.text = [NSString stringWithFormat:@"+%@步",healthModel.pedometer];
        }
    }else if ([self.currentTypeStr intValue] == 7){
        // 体温
        cell.contentLabel.text = [NSString stringWithFormat:@"%@摄氏度",healthModel.temperature];
    }else if ([self.currentTypeStr intValue] == 3){
        // 心率
        cell.contentLabel.text = [NSString stringWithFormat:@"%@次/分",healthModel.heartrate];
    }else if ([self.currentTypeStr intValue] == 8){
        //  血压
        bloodCell.bloodPressureLabel.text = [NSString stringWithFormat:@"收缩压%@mmHg 舒张压%@mmHg",healthModel.systolic_pressure,healthModel.diastolic_pressure];
        bloodCell.timeLabel.text = timeString;
    }else if ([self.currentTypeStr intValue] == 15){
        //  餐后血糖
        cell.contentLabel.text = [NSString stringWithFormat:@"餐后 %@mmol/L",healthModel.ppbs];
    }else if ([self.currentTypeStr intValue] == 9){
        //  餐前血糖
        cell.contentLabel.text = [NSString stringWithFormat:@"餐前 %@mmol/L",healthModel.ppbg];
    }else if ([self.currentTypeStr intValue] == 12){
        //  身高
        cell.contentLabel.text = [NSString stringWithFormat:@"%@cm",healthModel.height];
    }else if ([self.currentTypeStr intValue] == 13){
        //  体重
        cell.contentLabel.text = [NSString stringWithFormat:@"%@kg",healthModel.weight];
    }else if ([self.currentTypeStr intValue] == 14){
        //  BMI
        cell.contentLabel.text = [NSString stringWithFormat:@"%@",healthModel.bmi];
    }else if ([self.currentTypeStr intValue] == 2){
        cell.contentLabel.text = [NSString stringWithFormat:@"左眼:%@ 右眼:%@",healthModel.left_vision,healthModel.right_vision];
    }else if ([self.currentTypeStr intValue] == 11){
        //  柔韧性
        cell.contentLabel.text = [NSString stringWithFormat:@"%@秒",healthModel.flexility];
    }else if ([self.currentTypeStr intValue] == 10){
        //  挥拳
        cell.contentLabel.text = [NSString stringWithFormat:@"%@次/10秒",healthModel.shake_fist];
    }else if ([self.currentTypeStr intValue] == 5){
        //  色觉
        cell.contentLabel.text = [NSString stringWithFormat:@"%@",healthModel.colorvision];
    }
    
    if ([self.naviTitleStr isEqualToString:@"血压"]) {
        [bloodCell.bloodPressureButton addTarget:self action:@selector(cellBloodPressureButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        if (editImportSignsChange) {
            //最终的位置
            [bloodCell.bloodPressureButton setBackgroundImage:[UIImage imageNamed:@"日志_删除"] forState:UIControlStateNormal];
            if (kScreenWidth == 414) {
                bloodCell.jumpImageView.frame = CGRectMake(kScreenWidth + 10, 27, 18, 18);
            }else{
                bloodCell.jumpImageView.frame = CGRectMake(kScreenWidth + 10, 23, 15, 15);
            }
        }else{
            [bloodCell.bloodPressureButton setBackgroundImage:[UIImage imageNamed:@"日志_内容"] forState:UIControlStateNormal];
            if (kScreenWidth == 414) {
                bloodCell.jumpImageView.frame = CGRectMake(kScreenWidth - 33 , 27, 18, 18);
            }else{
                bloodCell.jumpImageView.frame = CGRectMake(kScreenWidth - 30 , 23, 15, 15);
            }
        }
        return bloodCell;
    }else{
        [cell.editButton addTarget:self action:@selector(cellEditButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        if (editImportSignsChange) {
            //最终的位置
            [cell.editButton setBackgroundImage:[UIImage imageNamed:@"日志_删除"] forState:UIControlStateNormal];
            if (kScreenWidth == 414) {
                cell.timeLabel.frame = CGRectMake(kScreenWidth -  150 - 18, 20, 150, 15);
                cell.jumpImageView.frame = CGRectMake(kScreenWidth + 10, 18, 18, 18);
            }else{
                cell.timeLabel.frame = CGRectMake(kScreenWidth - 165, 14, 150, 15);
                cell.jumpImageView.frame = CGRectMake(kScreenWidth + 10, 15, 15, 15);
            }
            MyNSLog("==========%f",kScreenWidth);
        }else{
            [cell.editButton setBackgroundImage:[UIImage imageNamed:@"日志_内容"] forState:UIControlStateNormal];
            if (kScreenWidth == 414) {
                cell.timeLabel.frame = CGRectMake(kScreenWidth -  150 - 18 - 15, 20, 150, 15);
                cell.jumpImageView.frame = CGRectMake(kScreenWidth - 33 , 18, 18, 18);
            }else{
                cell.timeLabel.frame = CGRectMake(kScreenWidth -  180, 14, 150, 15);
                cell.jumpImageView.frame = CGRectMake(kScreenWidth - 30 , 15, 15, 15);
            }
        }
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!editImportSignsChange) {
        if ([self.naviTitleStr isEqualToString:@"记步记录"] || [self.naviTitleStr isEqualToString:@"柔韧性"] || [self.naviTitleStr isEqualToString:@"挥拳"] || [self.naviTitleStr isEqualToString:@"色觉"]) {
            BaseSignDetailsViewController *baseSignDetailVC = [[BaseSignDetailsViewController alloc] init];
            baseSignDetailVC.healthDataSource = [self.healthDataSourceArray objectAtIndex:indexPath.row];
            baseSignDetailVC.detailsTypeStr = self.naviTitleStr;
            [self.navigationController pushViewController:baseSignDetailVC animated:YES];
        }else{
            ImportSignDatailViewController *importSignDatailVC = [[ImportSignDatailViewController alloc] init];
            MyHealthLogModel *model = [[MyHealthLogModel alloc] init];
            model = [self.healthDataSourceArray objectAtIndex:indexPath.row];
            
            MyNSLog("%@", model.inputtype);
            if ([model.ppbg intValue] > 0) {
                importSignDatailVC.bloodInteger = 100;
            }else if ([model.ppbs intValue] > 0){
                importSignDatailVC.bloodInteger = 200;
            }
            importSignDatailVC.healthModel = model;
            importSignDatailVC.detailsTypeStr = self.naviTitleStr;
            [self.navigationController pushViewController:importSignDatailVC animated:YES];
        }
        MyNSLog("我触发了方法 %d", indexPath.row);
    }else{
        MyNSLog("我是不会触发方法的");
    }
}



//设置tableView每一行的编辑样式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}


//设置删除时显示的文字
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!editImportSignsChange) {
        return YES;
    }else if (editImportSignsChange){
        return NO;
    };
    return YES;
}

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}


//触发删除按钮的方法
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
     MyHealthLogModel *CurrentCellModel = [self.healthDataSourceArray objectAtIndex:indexPath.row];
    [self.deleteDic setValue:CurrentCellModel.logid forKey:@"logid"];
    [self.deleteDic setValue:CurrentCellModel.dateline forKey:@"dateline"];
    self.selfIndexpath = indexPath;
    [self deleteDataSource:kBaseURL];
    
    
}





#pragma mark - cell中button的执行方法 -
- (void)cellEditButtonAction:(UIButton *)sender{
    SignsDataCell *cell = nil;
    UIView  *view = sender.superview;
    for (NSInteger i = 0; i < 1; ) {
        if ([view isKindOfClass:[SignsDataCell class]]) {
            cell = (SignsDataCell *)view;
            break;
        }else{
            view =view.superview;
        }
    }
    self.selfIndexpath = [self.editImportSignsTableView indexPathForCell:cell];
    if (controlMethod) {
        MyHealthLogModel *CurrentCellModel = [[MyHealthLogModel alloc] init];
        CurrentCellModel = [self.healthDataSourceArray objectAtIndex:self.selfIndexpath.row];
        [self.deleteDic setValue:CurrentCellModel.logid forKey:@"logid"];
        [self.deleteDic setValue:CurrentCellModel.dateline forKey:@"dateline"];
        [self deleteDataSource:kBaseURL];
    }
    
}

/**
 *   血压的数据处理
 */
- (void)cellBloodPressureButtonAction:(UIButton *)sender{
    BloodPressureCell *cell = nil;
    UIView  *view = sender.superview;
    for (NSInteger i = 0; i < 1; ) {
        if ([view isKindOfClass:[BloodPressureCell class]]) {
            cell = (BloodPressureCell *)view;
            break;
        }else{
            view =view.superview;
        }
    }
    self.selfIndexpath = [self.editImportSignsTableView indexPathForCell:cell];
    
    if (controlMethod) {
        MyHealthLogModel *CurrentCellModel = [[MyHealthLogModel alloc] init];
        CurrentCellModel = [self.healthDataSourceArray objectAtIndex:self.selfIndexpath.row];
        [self.deleteDic setValue:CurrentCellModel.logid forKey:@"logid"];
        [self.deleteDic setValue:CurrentCellModel.dateline forKey:@"dateline"];
        [self deleteDataSource:kBaseURL];
//        [self.editImportSignsTableView reloadData];
    }

}

#pragma mark - 懒加载 -
/**
 *  返回按钮
 *
 *  @return backButton
 */
- (UIButton *)backButton{
    if (_backButton == nil) {
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.backButton.frame = CGRectMake(0, 0, 23, 23);
        [self.backButton setImage:[UIImage imageNamed:@"公用_返回"] forState:UIControlStateNormal];
        self.backButton.titleLabel.font = [UIFont systemFontOfSize:13];
        self.backButton.titleLabel.textAlignment = NSTextAlignmentLeft;
        [self.backButton addTarget:self action:@selector(handleBackButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backButton;
}

/**
 *  编辑按钮
 *
 *  @return editButton
 */
- (UIButton *)editButton{
    if (_editButton == nil) {
        self.editButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.editButton.frame = CGRectMake(0, 0, 30, 23);
        [self.editButton setTitle:@"编辑" forState:UIControlStateNormal];
        self.editButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.editButton addTarget:self action:@selector(handleEditButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}


#pragma mark - 根据title判断当前页面的type类型 -
- (void)getCurrentTypeStr{
    if ([self.naviTitleStr isEqualToString:@"呼吸速率"]) {
        self.currentTypeStr = [NSString stringWithFormat:@"6"];
    }else if([self.naviTitleStr isEqualToString:@"体温"]){
        self.currentTypeStr = [NSString stringWithFormat:@"7"];
    }else if ([self.naviTitleStr isEqualToString:@"心率"]){
        self.currentTypeStr = [NSString stringWithFormat:@"3"];
    }else if ([self.naviTitleStr isEqualToString:@"血压"]){
        self.currentTypeStr = [NSString stringWithFormat:@"8"];
    }else if ([self.naviTitleStr isEqualToString:@"餐前血糖"]){
        self.currentTypeStr = [NSString stringWithFormat:@"9"];
    }else if ([self.naviTitleStr isEqualToString:@"记步记录"]){
        self.currentTypeStr = [NSString stringWithFormat:@"4"];
    }else if ([self.naviTitleStr isEqualToString:@"身高"]){
        self.currentTypeStr = [NSString stringWithFormat:@"12"];
    }else if ([self.naviTitleStr isEqualToString:@"体重"]){
        self.currentTypeStr = [NSString stringWithFormat:@"13"];
    }else if ([self.naviTitleStr isEqualToString:@"BMI"]){
        self.currentTypeStr = [NSString stringWithFormat:@"14"];
    }else if ([self.naviTitleStr isEqualToString:@"餐后血糖"]){
        self.currentTypeStr = [NSString stringWithFormat:@"15"];
    }else if ([self.naviTitleStr isEqualToString:@"血糖"]){
        self.currentTypeStr = [NSString stringWithFormat:@"9"];
    }else if ([self.naviTitleStr isEqualToString:@"视力"]){
        self.currentTypeStr = [NSString stringWithFormat:@"2"];
    }else if ([self.naviTitleStr isEqualToString:@"柔韧性"]){
        self.currentTypeStr = [NSString stringWithFormat:@"11"];
    }else if ([self.naviTitleStr isEqualToString:@"挥拳"]){
        self.currentTypeStr = [NSString stringWithFormat:@"10"];
    }else if ([self.naviTitleStr isEqualToString:@"色觉"]){
        self.currentTypeStr = [NSString stringWithFormat:@"5"];
    }
}


#pragma mark - 网路数据上传 (执行删除操作)-
- (void)deleteDataSource:(NSString *)urlString{
    [self showActionView];
    // 获取url地址
    NSString * postURL = [NSString stringWithFormat:@"%@user/logdel/",urlString];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [self.deleteDic setValue:kPlatform forKey:@"platform"];
    [self.deleteDic setValue:kVersion forKey:@"version"];
    [self.deleteDic setValue:self.currentTypeStr forKey:@"type"];
    
    [manager POST:postURL parameters:self.deleteDic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            [self showCustomHudSingleLine:@"删除失败"];
        }else{
            MyNSLog("========%@========", [responseObject objectForKey:@"msg"]);
            [self.healthDataSourceArray removeObjectAtIndex:self.selfIndexpath.row];
        }
        [self.editImportSignsTableView reloadData];
        [self hiddenActionView];
    } failure:nil];
}


#pragma mark - 网路数据请求 -

- (void)_parseHealthDataSource{
    [self showActionView];
    // 获取url地址
    NSString * postURL = [NSString stringWithFormat:@"%@user/log/",kBaseURL];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:kPlatform forKey:@"platform"];
    [parameters setValue:kVersion forKey:@"version"];
    MyNSLog("type类型 = %@", self.currentTypeStr);
    [parameters setValue:self.currentTypeStr forKey:@"type"];
    [parameters setValue:[NSString stringWithFormat:@"%ld",(long)pages] forKey:@"page"];
    [parameters setValue:[UserId shareUid].uidStr forKey:@"uid"];
    MyNSLog("参数字典 == %@", parameters);
    if (self.dataTimeStr.length > 0) {
        MyNSLog("======%@", self.dataTimeStr);
        if ([self.dataTimeStr isEqualToString:@"今天"]) {
            [parameters setValue:[self setNewTime] forKey:@"daytime"];
        }else{
            [parameters setValue:self.dataTimeStr forKey:@"daytime"];
        }
    }
    NSLog(@"%@",parameters);
    MyNSLog("==%@", self.currentTypeStr);
    MyNSLog("参数 ==== %@", parameters);
    [manager POST:postURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSNumber *statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        NSString *statusString = [numberFormatter stringFromNumber:statusNum];
        [self hiddenActionView];
        if ([statusString isEqualToString:@"0"]) {
            if (self.healthDataSourceArray.count > 0) {
                [self.editImportSignsTableView footerEndRefreshing];
            }else{
                [self showCustomHudSingleLine:@"暂无数据"];
            }
        }else{
            NSMutableArray *array = [[responseObject objectForKey:@"data"] isEqual:[NSNull null]]?nil:[responseObject objectForKey:@"data"];
            MyNSLog("数组 = %@", array);
            if (array != nil) {
                pages++;
                for (NSInteger i = 0; i < array.count; i++) {
                    MyHealthLogModel *healthModel = [[MyHealthLogModel alloc] init];
                    [healthModel setValuesForKeysWithDictionary:[array objectAtIndex:i]];
                    
                    if ([self.currentTypeStr intValue] == 9){
                        if ([[NSString stringWithFormat:@"%@",healthModel.ppbg] rangeOfString:@"."].location == NSNotFound) {
                            NSInteger ppbg = [healthModel.ppbg integerValue];
                            healthModel.ppbg = [NSString stringWithFormat:@"%ld",ppbg];
                        }else{
                            NSArray *arr = [[NSString stringWithFormat:@"%@",healthModel.ppbg] componentsSeparatedByString:@"."];
                            NSString *str = [NSString stringWithFormat:@"%@",arr.lastObject];
                            if (str.length == 1) {
                                float ppbg = [healthModel.ppbg floatValue];
                                healthModel.ppbg = [NSString stringWithFormat:@"%.1f",ppbg];
                            }else{
                                float ppbg = [healthModel.ppbg floatValue];
                                healthModel.ppbg = [NSString stringWithFormat:@"%.2f",ppbg];
                            }
                        }
                    }
                    if ([self.currentTypeStr intValue] == 15) {
                        if ([[NSString stringWithFormat:@"%@",healthModel.ppbs] rangeOfString:@"."].location == NSNotFound) {
                            NSInteger ppbs = [healthModel.ppbs integerValue];
                            healthModel.ppbs = [NSString stringWithFormat:@"%ld",ppbs];
                        }else{
                            NSArray *arr = [[NSString stringWithFormat:@"%@",healthModel.ppbs] componentsSeparatedByString:@"."];
                            NSString *str = [NSString stringWithFormat:@"%@",arr.lastObject];
                            if (str.length == 1) {
                                float ppbs = [healthModel.ppbs floatValue];
                                healthModel.ppbs = [NSString stringWithFormat:@"%.1f",ppbs];
                            }else{
                                float ppbs = [healthModel.ppbs floatValue];
                                healthModel.ppbs = [NSString stringWithFormat:@"%.2f",ppbs];
                            }
                        }
                       
                    }
                    [self.healthDataSourceArray addObject:healthModel];
                }
                [self.editImportSignsTableView reloadData];
            }else if ([array count] < 20){
                [self.editImportSignsTableView footerEndRefreshing];
            }
            MyNSLog("获取到的字典=====%@", array);
        }
        [self.editImportSignsTableView footerEndRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        [self.editImportSignsTableView footerEndRefreshing];
    }];
}

#pragma mark - 获取的时间戳转换为时间 -
- (NSString *)getDate:(NSString *)string{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    NSDate *theday = [NSDate dateWithTimeIntervalSince1970:[string doubleValue]];
    return [dateFormatter stringFromDate:theday];
    
//    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
//    [formatter setDateStyle:NSDateFormatterMediumStyle];
//    [formatter setTimeStyle:NSDateFormatterShortStyle];
//    //    [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
//    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
//    [formatter setTimeZone:timeZone];
//    [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
//    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[string integerValue]];
//    NSString *dateStr = [formatter stringFromDate:date];
//    return dateStr;
}

#pragma mark - 懒加载 -
- (NSMutableArray *)healthDataSourceArray{
    if (_healthDataSourceArray == nil) {
        self.healthDataSourceArray = [NSMutableArray array];
    }
    return _healthDataSourceArray;
}

- (NSMutableDictionary *)deleteDic{
    if (_deleteDic == nil) {
        self.deleteDic = [NSMutableDictionary dictionary];
    }
    return _deleteDic;
}

#pragma mark - 获取当前的时间 -
- (NSString *)setNewTime{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSString *locationString=[formatter stringFromDate: [NSDate date]];
    return locationString;
    
}
//- (NSString *)setNewTime{
//    NSDate *now = [NSDate date];
//    NSCalendar *calendar = [NSCalendar currentCalendar];
//    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
//    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
//    int year = [dateComponent year];
//    int month = [dateComponent month];
//    int day = [dateComponent day];
//    NSString *times = [NSString stringWithFormat:@"%d-%d-%d",year,month,day];
//    return times;
//}


#pragma mark - 获取血糖 - 
- (NSMutableArray *)getBloodSugarDataArr{
    NSMutableArray *array = [NSMutableArray array];
    MyHealthLogModel *currentCellModel = [[MyHealthLogModel alloc] init];
    for (NSInteger i = 0; i < self.healthDataSourceArray.count; i++) {
        currentCellModel = self.healthDataSourceArray[i];
        if ([currentCellModel.ppbg intValue] > 0) {
            [array addObject:currentCellModel.ppbg];
        }
        if ([currentCellModel.ppbs intValue] > 0){
            [array addObject:currentCellModel.ppbs];
        }
    }
    return array;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
